<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<form action="https://api.apiopen.top/developerRegister" method="post">
			<label>用户名:</label><input type="text" name="name" id="uname" /> <span id="uspan"
				style="color: #FF0000;"></span>
			<hr />
			<label>密码:</label><input type="password" name="passwd" id="pwd" /> <span id="pspan"
				style="color: #FF0000;"></span>
			<hr />
			<label>邮箱:</label><input type="email" name="email" id="email" />
			<hr />
			<!-- <button type="submit">注册</button> -->
			<button type="button">注册</button>
		</form>
		<script type="text/javascript">
			uname.addEventListener("change", function() {
				checkName();
			});

			function checkName() {
				var flag = false;
				var uname = document.querySelector("#uname");
				var reg = /^[a-z0-9_-]{3,15}$/;
				var uspan = document.querySelector("#uspan");
				if (!reg.test(uname.value)) {
					uspan.innerHTML = "格式错误";
				} else {
					uspan.innerHTML = "";
					flag = true;
				}
				return flag;
			}

			function checkPasswd() {
				var flag = false;
				var pwd = document.querySelector("#pwd");
				var reg = /^[0-9_-]{3,6}$/;
				var pspan = document.querySelector("#pspan");
				if (!reg.test(pwd.value)) {
					pspan.innerHTML = "格式错误";
				} else {
					pspan.innerHTML = "";
					flag = true;
				}
				return flag;
			}

			pwd.addEventListener("change", function() {
				checkPasswd();
			})

			var button = document.querySelector("button");
			button.addEventListener("click", function() {
				var uname = document.querySelector("#uname");
				if (checkName() && checkPasswd()) {
					var pwd = document.querySelector("#pwd");
					var email = document.querySelector("#email");
					var str = "name=" + uname.value + "&passwd=" + pwd.value + "&email=" + email.value;
					var xhr = new XMLHttpRequest();
					xhr.open("POST", "https://api.apiopen.top/developerRegister");
					xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
					xhr.send(str);
					xhr.onreadystatechange = function() {
						if (xhr.readyState == 4 && xhr.status == 200) {
							// var jsonStr = xhr.responseText;
							// var div = document.querySelector("div");
							// var jsonObj = JSON.parse(jsonStr);
							// div.innerHTML = jsonObj.result.apiKey;
							location.replace("65登录页面.html");
							// window.open("65登录页面.html");
						}else{
							
						}
					}
				}
			})
		</script>
	</body>
</html>
